package com.gps.skyrc.tool;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Create by ywq
 * data 2018/12/13
 */
public class StaticUtils {

    /**
     * 时间戳转字符串
     */
    public static String timesDate(long timesTamp, String format) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.getDefault());
        Date date = new Date(timesTamp * 1000);
        return dateFormat.format(date);
    }

    /**
     * 字符串转时间戳
     *
     * 例如：time 格式：
     */
    public static String timesTamp(String time,String format) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.getDefault());
        String times = null;
        try {
            Date date = dateFormat.parse(time);
            times = String.valueOf(date.getTime() / 1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return times;

    }

    /**
     * 格式化字符串
     */
    public static String stringFormat(String format, Object... objects) {
        return String.format(Locale.getDefault(), format, objects);
    }
}
